package web.config;

import org.springframework.aop.config.AopConfigUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class AopConfig {
    @Bean
    BeanDefinitionRegistryPostProcessor exposeProxyEnable() {
        // https://blog.csdn.net/f641385712/article/details/93475774
        return new BeanDefinitionRegistryPostProcessor() {
            @Override
            public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
                AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
            }

            @Override
            public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
                // BeanDefinition beanDefinition = beanFactory.getBeanDefinition(ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
                // BeanDefinition beanDefinition = beanFactory.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
                // beanDefinition.getPropertyValues().add("exposeProxy", true);
            }
        };
    }
}